package com.diallom.bd;


import com.diallom.R;
import com.diallom.parkingnord.ParkingNord;

import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Toast;

public class ParkingDAO extends Activity {
	private ParkingDB db;
	private EditText name,nbplaces,stationnement;
	private RatingBar note;
	private Parking pkg;
	private Button save,update;
	private Location location;
	private static float noterating=(float) 0.0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_parking);
		name = (EditText) findViewById(R.id.new_parking_name);
		nbplaces = (EditText) findViewById(R.id.new_parking_nbplaces);
		stationnement = (EditText) findViewById(R.id.new_parking_stationement_name);
		note = (RatingBar) findViewById(R.id.new_parking_note);
		
		save = (Button) findViewById(R.id.save_parking);
		
		pkg = new Parking();
		db = new ParkingDB(this);
		location = new Location("");
		
		note.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
			
			public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
				noterating=rating;
				Toast.makeText(ParkingDAO.this, noterating+"", Toast.LENGTH_SHORT).show();
			}
		});
		//db.reinit();
	}
	
	public void saveParking(View view){
		pkg.setNameParking(name.getText().toString());
		pkg.setNbOfPlaces(new Integer(nbplaces.getText().toString()));
		pkg.setStationnement(stationnement.getText().toString());
		pkg.setNote(new Float(noterating));
		pkg.setLocation(location);
		db.addParking(pkg);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.new_parking, menu);
		return true;
	}

}
